# -*- coding: utf-8 -*-
# @Time : 2021/4/12 5:13 下午
# @Author : Houor
# @Site : https://my.oschina.net/houor
# @File : ba-network.py
# @Description:


import matplotlib.pyplot as plt
import networkx as nt
import pandas as pd

ba = nt.barabasi_albert_graph(5000, 1)  # 生产BA网络
pos = nt.spring_layout(ba)

# 根据度数调整颜色
degree = ba.degree()
node_color_pd = pd.DataFrame(degree)
node_color3 = node_color_pd.iloc[:, 1]
edge_color = range(ba.number_of_edges())  # 设置边权颜色

nt.draw(ba, pos, with_labels=False, node_size=node_color3 * 6, node_color=node_color3 * 5, edge_color=edge_color)

plt.savefig('ba.jpg', dpi=600)
plt.show()

degree = nt.degree_histogram(ba)  # 生成所有节点的度分布序列
x = range(len(degree))  # X轴
y = [z for z in degree]  # Y轴：频次
plt.loglog(x, y, '.')

plt.savefig('ba_log.jpg', dpi=300)
plt.show()
